<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>结算账户</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
		<style type="text/css">
			td .layui-table-cell {
				text-align: center;
				height: 100px;
				white-space: normal;
			}

			.layui-table img,
			.layui-table video {
				width: 50px;
				max-width: 60px;
			}

			td .layui-table-cell {
				text-align: center;
				height: auto;
				white-space: normal;
			}

			.tDiv {
				font-size: 10px;
				line-height: 13px;
			}

			.tDiv-price {
				font-size: 15px;
				line-height: 18px;
			}
		</style>

	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header">订单信息</div>
						<!-- <div class="layui-card-header">
							<button class="layui-btn layui-btn-danger layui-btn-sm" id="del">删除</button>
						</div> -->
						<div class="layui-card-body">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">时间段：</label>
									<div class="layui-input-inline" style="width: 300px;">
										<input class="layui-input" id="choosetime" placeholder="时间段" autocomplete="off" value="">
										<input class="layui-input" type="text" id="starttime" value="" name="starttime" placeholder="" autocomplete="off" style="display: none;">
										<input class="layui-input" type="text" id="endtime" value="" name="endtime" placeholder="" autocomplete="off" style="display: none;">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">应用编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="settle_account_app_id" name="app_id"  placeholder="应用编号" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">结算账户：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="settle_account_id" name="settle_account_id"  placeholder="结算账户" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员ID：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="member_id" name="member_id" placeholder="会员ID" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">身份证：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="cert_id" name="cert_id" placeholder="身份证" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">结算卡：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="card_id" name="card_id" placeholder="结算卡" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">姓名：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="card_name" name="card_name" placeholder="姓名" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">电话：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="tel_no" name="tel_no" placeholder="电话" autocomplete="off">
									</div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search"
									data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->
							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form', 'laydate'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					admin = layui.admin;
				laydate.render({
					elem: '#choosetime',
					type: 'datetime',
					range: true,
					 value: '',  // 将默认日期设为空字符串
					done: function(value, date) {
						$('input[name=starttime]').val(value.split(' - ')[0]);
						$('input[name=endtime]').val(value.split(' - ')[1]);
					}
				});
				
				if ($('#choosetime').val() !== '') {   // 判断 value 参数是否为空字符串
				  $("#starttime").val(getstartime());
				  $("#endtime").val(getendtime());
				  var _data = {
				    starttime: $("#starttime").val(),
				    endtime: $("#endtime").val(),
				  };
				}
				initdata();
				function initdata() {
					table.render({
						elem: '#test-table-operate',
						url: server.sys_settle_account_query,
						height: 'full-155',
						cellMinWidth: cellMinWidth,
						limit: limit,
						limits: limits,
						defaultToolbar: [  'exports', {
							title: '提示' //标题
							, layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
							, icon: 'layui-icon-tips' //图标类名
						}],
						toolbar: true,
						cols: [
							[
							{
								field: 'app_id',
								width: 350,
								title: '应用编号',
								event: 'app_id'
							}, {
								field: 'settle_account_id',
								width: 170,
								title: '结算账户',
								event: 'settle_account_id'
							}, {
								field: 'member_id',
								width: 200,
								title: '会员ID',
								event: 'member_id'
							}, {
								field: 'cert_id',
								width: 200,
								title: '身份证',
								event: 'cert_id'
						
							}, {
								field: 'card_id',
								width: 200,
								title: '结算卡',
								event: 'card_id'
							}, {
								field: 'card_name',
								width: 100,
								title: '姓名',
								event: 'card_name'
							}, {
								field: 'tel_no',
								width: 140,
								title: '电话',
								event: 'tel_no'
							}, {
								field: 'amt',
								width: 100,
								title: '金额',
							}, {
								field: 'addtime',
								width: 180,
								title: '时间',
							}, ]
						],
						page: true,
						where: _data,
						request: {
							pageName: 'page',
							limitName: 'size' //每页数据量的参数名，默认：limit
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.settle_account.pager.total, //解析数据长度
								"data": res.settle_account.data //解析数据列表
							};
						}
					});
				}

				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					_data = data.field
					initdata();
					return false;
				});

				$("button[type=reset]").on("click", function() {
					_data = {}
					document.getElementById("form").reset();
					setTimeout(()=>{
						$("#choosetime").val(getstartime()+' - '+getendtime())
						$("#starttime").val(getstartime())
						$("#endtime").val(getendtime())
						_data.starttime = $("#starttime").val()
						_data.endtime = $("#endtime").val()
						initdata();
					},100)
				});

				//监听表格复选框选择
				table.on('tool(test-table-operate)', function (obj) {
					console.log(obj)
					var key = obj.event
					var inputKey = obj.event
					if (key === 'card_app_id') {
						key = 'app_id'
					}
					var queryData = obj.data[key]
					$('input[name="' + inputKey + '"]').val(queryData)
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				
				function getstartime(){
					var today = new Date();
					var tYear = today.getFullYear();
					var tMonth = today.getMonth() + 1;
					var tDate = today.getDate();
					tMonth = doHandleMonth(tMonth)
					tDate = doHandleMonth(tDate)
					return tYear+"-"+tMonth+"-"+tDate+" 00:00:00";
				}
				function getendtime(){
					var today = new Date();
					var tYear = today.getFullYear();
					var tMonth = today.getMonth() + 1;
					var tDate = today.getDate();
					tMonth = doHandleMonth(tMonth)
					tDate = doHandleMonth(tDate)
					return tYear+"-"+tMonth+"-"+tDate+" 23:59:59";
				}
				function doHandleMonth(month){
					var m = month;
					if(month.toString().length == 1){
						m = "0" + month;
					}
					return m;
				}
			});
		</script>
	</body>

</html>
